/*-------------------------------------------------------------------------
 *
 * fls.c
 *	  找到最后一个（最重要的）被设置的位
 *
 * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
 *
 *
 * IDENTIFICATION
 *	  src/port/fls.c
 *
 * This file was taken from FreeBSD to provide an implementation of fls()
 * for platforms that lack it.  Note that the operating system's version may
 * be substantially more efficient than ours, since some platforms have an
 * assembly instruction that does exactly this.
 *
 * The FreeBSD copyright terms follow.
 */

/*-
 * Copyright (c) 1990, 1993
 *	The Regents of the University of California.  All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *	  notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *	  notice, this list of conditions and the following disclaimer in the
 *	  documentation和/或其他提供的材料中。
 * 4. Neither the name of the University nor the names of its contributors
 *	  may be used to endorse或推广基于此软件衍生的产品，
 *	  除非获得特定的书面许可。
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, 或利润；或业务中断)
 * 造成的损害，无论在任何理论责任下，
 * 无论在合同、严格责任或侵权（包括过失或其他）下，均不负任何责任，
 * 即使在被告知此类损害的可能性的情况下。
 */

#include "c.h"

/*
 * 查找最后一个设置的位
 */
int fls(int fc_mask)
{
	int			fc_bit;

	if (fc_mask == 0)
		return (0);
	for (fc_bit = 1; fc_mask != 1; fc_bit++)
		fc_mask = (unsigned int) fc_mask >> 1;
	return (fc_bit);
}
